using System;
using System.Collections.Generic;
using System.Text;
using TTDotNet.Util;

namespace TTDotNet.Engine.Networks
{
    public class AStarNode : IComparable<AStarNode>
    {
        private AStarNode parent;
        private DDDCoordinate coord;
        private int costToHere;
        private int costToDestination;
        private int totalCost;    

        public AStarNode(AStarNode parent, DDDCoordinate coord, int costToHere, int costToDestination)
        {
            this.coord = coord;
            this.costToHere = costToHere;
            this.costToDestination = costToDestination;
            this.totalCost = costToHere + costToDestination;
            this.parent = parent;
        }

        public DDDCoordinate Coordinate
        {
            get { return coord; }
        }

        public int CostToHere
        {
            get { return costToHere; }
        }

        public int TotalCost
        {
            get { return totalCost; }
        }

        public AStarNode Parent
        {
            get { return parent; }
            set { parent = value; }
        }

        public int CompareTo(AStarNode obj)
        {
            return totalCost - obj.TotalCost;
        }

        public bool IsGoal(DDDCoordinate goal)
        {
            return coord.Equals(goal);
        }

        public override bool Equals(object obj)
        {
            AStarNode node = (AStarNode)obj;
            return coord.Equals(node.Coordinate);  
        }

    }
}
